package com.yungu.swift.system.finance.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.service.impl.BaseServiceImpl;
import com.yungu.swift.system.finance.dao.FinanceInviteRewardMapper;
import com.yungu.swift.system.finance.model.dto.FinanceInviteRewardDto;
import com.yungu.swift.system.finance.model.param.AdminInviteRewardPageParam;
import com.yungu.swift.system.finance.model.vo.FinanceDriverRewardVo;
import com.yungu.swift.system.finance.service.FinanceInviteRewardService;
import com.yungu.swift.utils.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.List;

/**
 * 邀请奖励
 */
@Service
public class FinanceInviteRewardServiceImpl extends BaseServiceImpl<FinanceInviteRewardDto> implements
        FinanceInviteRewardService {
    @Autowired
    private FinanceInviteRewardMapper financeInviteRewardMapper;

    @Override
    protected IMapper<FinanceInviteRewardDto> getMapper() {
        return financeInviteRewardMapper;
    }

    @Override
    public ResponseData<PageVo<FinanceDriverRewardVo>> driverRewardPage(AdminInviteRewardPageParam rewardPageParam) {
        PageBounds pageBounds = new PageBounds(rewardPageParam.getPageNum(), rewardPageParam.getPageSize());
        PageList<FinanceDriverRewardVo> pageList = financeInviteRewardMapper.driverRewardPage(MapUtils.convertObjToMap(
                rewardPageParam), pageBounds);
        PageVo<FinanceDriverRewardVo> pageVo = new PageVo(rewardPageParam.getPageNum(), rewardPageParam.getPageSize(),
                pageList.getPaginator().getTotalCount());
        pageVo.setItems(pageList);
        return ResponseData.buildSuccessResponse(pageVo);
    }

    @Override
    public ResponseData<List<FinanceDriverRewardVo>> driverRewardExport(AdminInviteRewardPageParam rewardPageParam) {
        return ResponseData.buildSuccessResponse(financeInviteRewardMapper.driverRewardPage(MapUtils.convertObjToMap(
                rewardPageParam)));
    }

    @Override
    public ResponseData<BigDecimal> getSumDriverAwardAmount(String driverUuid, Integer course) {
        return ResponseData.buildSuccessResponse(financeInviteRewardMapper.getSumDriverAwardAmount(driverUuid, course));
    }
}